//=====================================================
//			 		          TGAImage.h
//		         Header of TGAImage class
//  		     Arquivo criado em 13/12/2010
//		     Microsoft Visual Studio C++ 2008
//
//				     Thiago Bragante Macedo
//              tmacedo29@gmail.com
//=====================================================

#ifndef TGA_IMAGE_H
#define TGA_IMAGE_H

#include <gendef.h>
#include <string>
using namespace std;

/// Definitions
///
/// Image Format
#define	IMAGE_RGB       0
#define IMAGE_RGBA      1
#define IMAGE_LUMINANCE 2
///
/// 
///
#define	IMAGE_DATA_UNSIGNED_BYTE 0
///
/// 
///
#define BOTTOM_LEFT  0x00
#define BOTTOM_RIGHT 0x10
#define TOP_LEFT     0x20
#define TOP_RIGHT    0x30
///
/// 
///
class TGAHeader
{
  public:
    unsigned char  SizeID;
	  unsigned char  ColorMapType;
	  unsigned char  ImageCodeType;
	  unsigned char  SpecularColorMap[5];
	  unsigned short X;
	  unsigned short Y;
	  unsigned short Width;
	  unsigned short Height;
	  unsigned char  BPP;
	  unsigned char  ImageDescr;
};

typedef enum TGATypes
{
	TGA_NODATA			  = 0,
	TGA_INDEXED			  = 1,
	TGA_RGB				    = 2,
	TGA_GRAYSCALE		  = 3,
	TGA_INDEXED_RLA	  = 9,
	TGA_RGB_RLE			  = 10,
	TGA_GRAYSCALE_RLE	= 11
};

class TGAImage
{
  private:
    ///
    /// Attributes
    ///
    unsigned char *_image;
    unsigned char  _colorDepth;
    unsigned short _width;
	  unsigned short _height;
    unsigned char  _imageFormat;
    unsigned char  _imageType;
    unsigned long  _imageSize;

    ///
    /// Methods
    ///
    void SwitchRedBlue(void);
    

  public:
    TGAImage();
    virtual ~TGAImage();

    bool Load ( const string& );
    void Free ( void );
    
    bool VerticalRotate ( void );

    bool ConvertRGBAtoRGB ( void );
    bool ConvertRGBtoRGBA ( unsigned char );

};

#endif
